<!--
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<div class="kd-bg-background"
     fxFlex
     fxLayoutAlign="space-around center">
  <kd-card titleClasses="kd-card-top-radius kd-bg-primary kd-accent"
           [expandable]="false">
    <div title
         i18n>Kubernetes Dashboard</div>
    <div content>
      <form fxLayout="column"
            (ngSubmit)="login()">
        <mat-radio-group name="login"
                         [(ngModel)]="selectedAuthenticationMode">
          <div *ngFor="let mode of getEnabledAuthenticationModes()">
            <mat-radio-button [value]="mode"
                              color="primary">
              <ng-container [ngSwitch]="mode">
                <ng-container *ngSwitchCase="loginModes.Kubeconfig"
                              i18n>Kubeconfig</ng-container>
                <ng-container *ngSwitchCase="loginModes.Basic"
                              i18n>Basic</ng-container>
                <ng-container *ngSwitchCase="loginModes.Token"
                              i18n>Token</ng-container>
              </ng-container>
            </mat-radio-button>
            <div class="kd-login-mode-description"
                 [ngSwitch]="mode">
              <ng-container *ngSwitchCase="loginModes.Kubeconfig"
                            i18n>
                Please select the kubeconfig file that you have created to configure access to the cluster. To find out more about how to configure and use kubeconfig file, please refer to the <a href='https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/'>Configure Access to Multiple Clusters</a> section.
              </ng-container>
              <ng-container *ngSwitchCase="loginModes.Basic"
                            i18n>
                Make sure that support for basic authentication is enabled in the cluster. To find out more about how to configure basic authentication, please refer to the <a href="https://kubernetes.io/docs/admin/authentication/">Authenticating</a> and <a href="https://kubernetes.io/docs/admin/authorization/abac/">ABAC Mode</a> sections.
              </ng-container>
              <ng-container *ngSwitchCase="loginModes.Token"
                            i18n>
                Every Service Account has a Secret with valid Bearer Token that can be used to log in to Dashboard. To find out more about how to configure and use Bearer Tokens, please refer to the <a href='https://kubernetes.io/docs/admin/authentication/'>Authentication</a> section.
              </ng-container>
            </div>
          </div>
        </mat-radio-group>

        <ng-container [ngSwitch]="selectedAuthenticationMode">
          <mat-form-field *ngSwitchCase="loginModes.Token"
                          class="kd-login-input">
            <input matInput
                   id="token"
                   name="token"
                   i18n-placeholder
                   placeholder="Enter token"
                   type="password"
                   required
                   (change)="onChange($event)">
          </mat-form-field>
          <div *ngSwitchCase="loginModes.Basic"
               fxLayout="column">
            <mat-form-field fxFlex
                            class="kd-login-input">
              <input id="username"
                     name="username"
                     matInput
                     i18n-placeholder
                     placeholder="Username"
                     required
                     (change)="onChange($event)">
            </mat-form-field>

            <mat-form-field fxFlex
                            class="kd-login-input">
              <input id="password"
                     name="password"
                     matInput
                     i18n-placeholder
                     placeholder="Password"
                     type="password"
                     required
                     (change)="onChange($event)">
            </mat-form-field>
          </div>

          <div *ngSwitchCase="loginModes.Kubeconfig"
               class="kd-login-input">
            <kd-upload-file label="Choose kubeconfig file"
                            i18n-label
                            (onLoad)="onChange($event)"></kd-upload-file>
          </div>
          <mat-error *ngFor="let error of errors"
                     class="kd-login-input kd-error kd-error-text">
            {{error.status}} ({{error.code}}): {{error.message}}
          </mat-error>
          <mat-error *ngIf="!isLoginEnabled()"
                     class="kd-login-input kd-error kd-error-text"
                     i18n>
            Insecure access detected. Sign in will not be available. Access Dashboard securely over HTTPS or using localhost. Read more
            <a href="https://github.com/kubernetes/dashboard/blob/master/docs/user/accessing-dashboard/README.md#login-not-available"
               target="_blank">
              here
            </a>.
          </mat-error>
        </ng-container>

        <div fxFlex="none"
             fxLayout="row">
          <button mat-raised-button
                  color="primary"
                  type="submit"
                  class="kd-login-button"
                  [disabled]="!isLoginEnabled()"
                  i18n>
            Sign in
          </button>
          <button mat-button
                  color="primary"
                  type="button"
                  class="kd-login-button"
                  *ngIf="isSkipButtonEnabled()"
                  (click)="skip()"
                  i18n>
            Skip
          </button>
        </div>
      </form>
    </div>
  </kd-card>
</div>
